﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChallengePuzzle.Lib
{
    /// <summary>
    /// 数组累加器
    /// </summary>
    public class PlusSum3 : ChallengePuzzle.Lib.IPlusSum
    {
        int PreValue = 0;

        public int GetPlusSum(int Number)
        {
            int LessNum = Number % 10;

            if (LessNum != 0)
            {
                PreValue++;
                return PreValue;
            }

            PreValue = GetPlusSum1(Number);

            return PreValue;

        }


        //--------------------------------------------------------------------------


        public int GetPlusSum2(int Number)
        {
            int DivNum = Number / 10;

            int LessNum = Number % 10;

            if (DivNum < 10) return DivNum + LessNum;

            return GetPlusSum1(DivNum) + LessNum;
        }


        public int GetPlusSum1(int n)
        {
            int sum = 0, m = 1; 
            while (n>10) 
            { 
                m = n % 10;
                sum = sum + m; 
                n = n / 10; 
            }

            return sum;
        }






    }
}
